'''
each header is defined as a list of tuples,
each tuple consisting of 3 elements: (name, type, offset)

this allows us to modify the header list and pack into 
numpy dtypes as required.

sfletcher, 20211209
'''
import numpy as np

segy_binary_header = [
	('jobid', 'i4', 0),
	('lino', 'i4', 4),
	('reno', 'i4', 8),
	('ntrpr', 'i2', 12),
	('nart', 'i2', 14), 
	('hdt', 'u2', 16), 
	('dto', 'u2', 18),
	('hns', 'u2', 20), 
	('nso', 'u2', 22),
	('format', 'i2', 24), 
	('fold', 'i2', 26),
	('tsort', 'i2', 28), 
	('vscode', 'i2', 30),
	('hsfs', 'i2', 32),
	('hsfe', 'i2', 34),
	('hslen', 'i2', 36),
	('hstyp', 'i2', 38),
	('schn', 'i2', 40),
	('hstas', 'i2', 42),
	('hstae', 'i2', 44),
	('htatyp', 'i2', 46),
	('hcorr', 'i2', 48),
	('bgrcv', 'i2', 50),
	('rcvm', 'i2', 52),
	('mfeet', 'i2', 54),
	('polyv', 'i2', 56),
	('vpol', 'i2', 58),
	('unassigned_1', ('B',   240), 60),
	('segyrev', 'i2', 300),
	('fixedlen', 'i2', 302),
	('numhdr', 'i2', 304), 
	('unassigned_2', ('B', 94), 306),
]

segy_trace_header=[
	('tracl',  'i4', 0), # strongly recommended
	('tracr',  'i4', 4),
	('fldr',   'i4', 8), # strongly recommended
	('tracf',  'i4', 12), # strongly recommended
	('ep',     'i4', 16),
	('cdp',    'i4', 20),
	('cdpt',   'i4', 24),
	('trid',   'i2', 28), # strongly recommended
	('nvs',    'i2', 30),
	('nhs',    'i2', 32),
	('duse',   'i2', 34),
	('offset', 'i4', 36),
	('gelev',  'i4', 40),
	('selev',  'i4', 44),
	('sdepth', 'i4', 48),
	('gdel',   'i4', 52),
	('sdel',   'i4', 56),
	('swdep',  'i4', 60),
	('gwdep',  'i4', 64),
	('scalel', 'i2', 68),
	('scalco', 'i2', 70),
	('sx',     'i4', 72),
	('sy',     'i4', 76),
	('gx',     'i4', 80),
	('gy',     'i4', 84),
	('counit', 'i2', 88),
	('wevel',   'i2', 90),
	('swevel',  'i2', 92),
	('sut',     'i2', 94),
	('gut',     'i2', 96),
	('sstat',   'i2', 98),
	('gstat',   'i2', 100),
	('tstat',   'i2', 102),
	('laga',    'i2', 104),
	('lagb',    'i2', 106),
	('delrt',   'i2', 108),
	('muts',    'i2', 110),
	('mute',    'i2', 112),
	('ns',      'i2', 114), # strongly recommended
	('dt',      'i2', 116), # strongly recommended
	('gain',    'i2', 118),
	('igc',    'i2', 120),
	('igi',    'i2', 122),
	('corr',   'i2', 124),
	('sfs',    'i2', 126),
	('sfe',    'i2', 128),
	('slen',   'i2', 130),
	('styp',   'i2', 132),
	('stas',   'i2', 134),
	('stae',   'i2', 136),
	('tatyp',  'i2', 138),
	('afilf',  'i2', 140),
	('afils',  'i2', 142),
	('nofilf', 'i2', 144),
	('nofils', 'i2', 146),
	('lcf',    'i2', 148),
	('hcf',    'i2', 150),
	('lcs',    'i2', 152),
	('hcs',    'i2', 154),
	('year',   'i2', 156),
	('day',    'i2', 158),
	('hour',   'i2', 160),
	('minute', 'i2', 162),
	('sec',    'i2', 164),
	('timbas', 'i2', 166),
	('trwf',   'i2', 168),
	('grnors', 'i2', 170),
	('grnofr', 'i2', 172),
	('grnlof', 'i2', 174),
	('gaps',   'i2', 176),
	('otrav',  'i2', 178),
	('cdpx',   'i4', 180),
	('cdpy',   'i4', 184),
	('iline',  'i4', 188),
	('xline',  'i4', 192),
	('shnum',  'i4', 196),
	('shsca',  'i2', 200),
	('tval',   'i2', 202),
	('tconst4', 'i4', 204),
	('tconst2', 'i2', 208),
	('tunits', 'i2', 210),
	('device', 'i2', 212),
	('tscalar', 'i2', 214),
	('stype',  'i2', 216),
	('sendir2', 'i2', 218),
	('sendir4', 'i4', 220),
	('smeas4', 'i4', 224),
	('smeas2', 'i2', 228),
	('smeasu', 'i2', 230),
	('unass1', 'i4', 232),
	('unass2', 'i4', 236)]

su_trace_header = [
    ('tracl', np.int32,0),
    ('tracr', np.int32,4),
    ('fldr', np.int32,8),
    ('tracf', np.int32,12),
    ('ep', np.int32,16),
    ('cdp', np.int32,20),
    ('cdpt', np.int32,24),
    ('trid', np.int16,28),
    ('nvs', np.int16,30),
    ('nhs', np.int16,32),
    ('duse', np.int16,34),
    ('offset', np.int32,36),
    ('gelev', np.int32,40),
    ('selev', np.int32,44),
    ('sdepth', np.int32,48),
    ('gdel', np.int32,52),
    ('sdel', np.int32,56),
    ('swdep', np.int32,60),
    ('gwdep', np.int32,64),
    ('scalel', np.int16,68),
    ('scalco', np.int16,70),
    ('sx', np.int32,72),
    ('sy', np.int32,76),
    ('gx', np.int32,80),
    ('gy', np.int32,84),
    ('counit', np.int16,88),
    ('wevel', np.int16,90),
    ('swevel', np.int16,92),
    ('sut', np.int16,94),
    ('gut', np.int16,96),
    ('sstat', np.int16,98),
    ('gstat', np.int16,100),
    ('tstat', np.int16,102),
    ('laga', np.int16,104),
    ('lagb', np.int16,106),
    ('delrt', np.int16,108),
    ('muts', np.int16,110),
    ('mute', np.int16,112),
    ('ns', np.uint16,114),
    ('dt', np.uint16,116),
    ('gain', np.int16,118),
    ('igc', np.int16,120),
    ('igi', np.int16,122),
    ('corr', np.int16,124),
    ('sfs', np.int16,126),
    ('sfe', np.int16,128),
    ('slen', np.int16,130),
    ('styp', np.int16,132),
    ('stas', np.int16,134),
    ('stae', np.int16,136),
    ('tatyp', np.int16,138),
    ('afilf', np.int16,140),
    ('afils', np.int16,142),
    ('nofilf', np.int16,144),
    ('nofils', np.int16,146),
    ('lcf', np.int16,148),
    ('hcf', np.int16,150),
    ('lcs', np.int16,152),
    ('hcs', np.int16,154),
    ('year', np.int16,156),
    ('day', np.int16,158),
    ('hour', np.int16,160),
    ('minute', np.int16,162),
    ('sec', np.int16,164),
    ('timebas', np.int16,166),
    ('trwf', np.int16,168),
    ('grnors', np.int16,170),
    ('grnofr', np.int16,172),
    ('grnlof', np.int16,174),
    ('gaps', np.int16,176),
    ('otrav', np.int16,178),
    ('d1', np.float32,180),
    ('f1', np.float32,184),
    ('d2', np.float32,188),
    ('f2', np.float32,192),
    ('ShotPoint', np.int32,196),
    ('unscale', np.int16,200),
    ('TraceValueMeasurementUnit', np.int16,202),
    ('TransductionConstantMantissa', np.int32,204),
    ('TransductionConstantPower', np.int16,208),
    ('TransductionUnit', np.int16,210),
    ('TraceIdentifier', np.int16,212),
    ('ScalarTraceHeader', np.int16,214),
    ('SourceType', np.int16,216),
    ('SourceEnergyDirectionMantissa', np.int32,218),
    ('SourceEnergyDirectionExponent', np.int16,222),
    ('SourceMeasurementMantissa', np.int32,224),
    ('SourceMeasurementExponent', np.int16,228),
    ('SourceMeasurementUnit', np.int16,230),
    ('UnassignedInt1', np.int32,232),
    ('ns1', np.int32,236),
]